package com.team.sion.mapper;

import com.team.sion.pojo.Song;
import com.team.sion.pojo.SongExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface SongMapper {
    long countByExample(SongExample example);

    int deleteByExample(SongExample example);

    @Delete({
        "delete from song",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into song (id, singer_id, ",
        "name, introduction, ",
        "createTime, updateTime, ",
        "lyric, url, pic)",
        "values (#{id,jdbcType=INTEGER}, #{singerId,jdbcType=INTEGER}, ",
        "#{name,jdbcType=VARCHAR}, #{introduction,jdbcType=VARCHAR}, ",
        "#{createtime,jdbcType=DATE}, #{updatetime,jdbcType=DATE}, ",
        "#{lyric,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, #{pic,jdbcType=VARCHAR})"
    })
    int insert(Song row);

    int insertSelective(Song row);

    List<Song> selectByExample(SongExample example);

    @Select({
        "select",
        "id, singer_id, name, introduction, createTime, updateTime, lyric, url, pic",
        "from song",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("com.team.sion.mapper.SongMapper.BaseResultMap")
    Song selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("row") Song row, @Param("example") SongExample example);

    int updateByExample(@Param("row") Song row, @Param("example") SongExample example);

    int updateByPrimaryKeySelective(Song row);

    @Update({
        "update song",
        "set singer_id = #{singerId,jdbcType=INTEGER},",
          "name = #{name,jdbcType=VARCHAR},",
          "introduction = #{introduction,jdbcType=VARCHAR},",
          "createTime = #{createtime,jdbcType=DATE},",
          "updateTime = #{updatetime,jdbcType=DATE},",
          "lyric = #{lyric,jdbcType=VARCHAR},",
          "url = #{url,jdbcType=VARCHAR},",
          "pic = #{pic,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Song row);
    @ResultMap("com.team.sion.mapper.SongMapper.BaseResultMap")
    @Select("select * from song where singer_id in (select id from singer where name like '%${name}%')")
    List<Song> findBySingerName(String name);

    @Update("SET foreign_key_checks = 0")
    void closeForeignKey();
    @Update("SET foreign_key_checks = 1")
    void openForeignKey();
}